<?
class System{//Lop he thong,Cac ham dung chung thong dung cho vao day
    static $false = false;

    static function sendEBEmail($to, $subject, $content,$FromNameMail = '', $images = array())
    {
    	$FromNameMail = WEB_NAME;
    	 
        require_once('includes/mailer/PHPMailer_v5.1/class.phpmailer.php');

        $mail = new PHPMailer();
        
        //$mail->CharSet 		= 'utf-8';
        $mail->IsSMTP();
        //$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
        //$mail->SetLanguage("vn",ROOT_PATH.'includes/mailer/PHPMailer_v5.1/');
        
		$mail->Host     	= SMTP_HOST;
        $mail->SMTPSecure 	= SMTP_SECURE;//For PHPMailer_v5.1
        $mail->Port     	= SMTP_PORT;
        $mail->SMTPAuth 	= SMTP_AUTH;
        $mail->SMTPSecure 	= SMTP_SECURE;

        $mail->Username 	= SMTP_USER;    	      // SMTP username
        $mail->Password 	= SMTP_PASS;              // SMTP password

        $mail->From     = SMTP_FROM_EMAIL;      	 // Email duoc gui tu???
        $mail->FromName = WEB_NAME;                  // Ten hom email duoc gui
    	//$mail->SetFrom(SMTP_FROM_EMAIL, WEB_NAME);
    	$mail->AddReplyTo(SMTP_FROM_EMAIL, WEB_NAME);
    	
        $mail->AddAddress($to,"");                    // Dia chi email va ten nhan

        $mail->Subject  =  $subject;                // Chu de email
        
        $mail->IsHTML(true);                        // Gui theo dang HTML
        $mail->Body    	=  $content;                // Noi dung html
        $mail->AltBody = 'Để xem được nội dung Email này, hãy sử dụng một trình duyệt Email tương thích với mã HTML! (To view the message, please use an HTML compatible email viewer!)'; //optional - MsgHTML will create an alternate automatically
        
        if(!empty($images)){
            $mail->message_type = 'attachments';
            foreach($images as $img){
                if(!empty($img)){
                    $ext = AZLib::getExtension($img['src']);
                    $img['mime'] = 'image/'.substr(strtolower($ext),1,strlen($ext));
                    $mail->AddEmbeddedImage($img['src'], $img['id'], $img['title'], 'base64', $img['mime']);
                }
            }
            //cau hinh nhu sau <img src="cid:ubzsed" />
        }
        
        if(!$mail->Send()){return false;}else{return true;}
    }
   
    static function halt(){
        exit();
    }
   
    static function debug($array){
        echo '<div align="left"><pre>';
        print_r($array);
        echo '</pre></div>';
    }
}
?>